package com.pubinfo.passbook.engine.cell.logic.medicine;

import com.pubinfo.passbook.common.entity.TPassbook;
import com.pubinfo.passbook.common.mapper.TSubsidiaryInfoMapper;
import com.pubinfo.passbook.common.model.bo.witeoff.CityInfo;
import com.pubinfo.passbook.common.model.dto.witeoff.MedicineOnJobOrRetireDTO;
import com.pubinfo.passbook.common.model.ruler.PayInformation;
import com.pubinfo.passbook.common.service.master.TPassbookService;
import com.pubinfo.passbook.common.service.ruler.CheckService;
import com.pubinfo.passbook.common.utils.ApplicationContextUilts;

import java.math.BigDecimal;
import java.util.List;

/**
 * 特殊病钟 或者 普通住院
 *
 * @author zhouch
 * @date 2022/2/21 8:42
 */
public class SpecialDiseasesOrHospitalUnit extends MedicineLogicUnit {


    TPassbookService passbookService;

    TSubsidiaryInfoMapper infoMapper;

    CheckService ruleService;

    public SpecialDiseasesOrHospitalUnit() {
        passbookService = ApplicationContextUilts.getBean(TPassbookService.class);
        infoMapper = ApplicationContextUilts.getBean(TSubsidiaryInfoMapper.class);
        ruleService = ApplicationContextUilts.getBean(CheckService.class);
    }

    @Override
    public Boolean then(MedicineOnJobOrRetireDTO data, BigDecimal result) {
        List<PayInformation> payInformations = cache.getPayInformationData();
        TPassbook passbook = passbookService.getPassbookById(data.getInvoiceIds()).get(0);
        // 报账人身份证号码
        String idNo = passbook.getPayerPartyCode();
        CityInfo info = infoMapper.findCityInfoByNsrsbh(passbook.getNsrsbh());

        return ruleService.isSpecialDiseases(info.getDistrictName(), idNo) || payInformations.get(0).getReimbursementType() == 1;
    }

    @Override
    public String getName() {
        return "是否特殊病种或者住院";
    }
}
